using System.Collections.Generic;
using Gameplay.RTS.ScriptConfig;
using UnityEditor;
using UnityEngine;
using Yoozoo.Mars.Got.SpriteAnim;

namespace Yoozoo.Gameplay.RTS
{
    public class BattleSpriteHelper
    {
        public static float DefaultSpeed = 1;
        
        private static Dictionary<string, Dictionary<SPRITE_ACTION_ENUM,List<Vector2>>> animTimeDic = new Dictionary<string, Dictionary<SPRITE_ACTION_ENUM, List<Vector2>>>();
        
        
        public static List<Vector2> GetAnimSpeedAndTimes(string modelName, SPRITE_ACTION_ENUM anim)
        {
            if (animTimeDic.TryGetValue(modelName, out var animTime))
            {
                if (animTime.TryGetValue(anim, out var list))
                {
                    return list;
                }
            }
            return null;
        }
        
        private static string GetSoldierModelNameById(int id)
        {
            return BattleUtils.GetSoldierModelNameById(id);
        }
        

        public static void AddSpriteActionFrame(SpriteActionFrame data)
        {
            if (!animTimeDic.TryGetValue(data.spriteName, out var dic))
            {
                dic = new Dictionary<SPRITE_ACTION_ENUM, List<Vector2>>();
                animTimeDic[data.spriteName] = dic;
            }
            for (int i = 0; i < data.actions.Count; i++)
            {
                var actionName = data.actions[i].actionName;
                var list = new List<Vector2>();
                for (int j = 0; j < data.actions[i].frames.Count; j++)
                {
                    var frameCount = data.actions[i].frames[j];
                    if (frameCount == 0)
                    {
                        frameCount = 1;
                    }
                    var speed = 1f / frameCount;
                    list.Add(new Vector2(speed,1 / 15f * frameCount));
                }
                var animation = SpriteFrameController.GetAnimationTypeByName(actionName);
                dic[animation] = list;
            }
        }
        
    }
}
